package com.ruoyi.tea.util;

import cc.casually.htmlParse.http.HttpClient;
import cc.casually.htmlParse.http.Request;
import cc.casually.htmlParse.http.Response;
import com.ruoyi.tea.cache.ConfCache;
import com.ruoyi.tea.task.RefreshConfCacheTask;

import java.io.UnsupportedEncodingException;

/**
 * 微信相关工具
 *
 * @author wangfeng
 * @time 2022年08月07日20:44:18
 */
public class WxChatUtil {

    /**
     * 文件获取mediaID
     *
     * @param path
     * @return
     */
    public static String fileToMedia(String path) {
        Request request = new Request();
        request.setUri("https://api.weixin.qq.com/cgi-bin/media/upload?type=image&access_token="+ConfCache.ACCESS_TOKEN );
        request.addBody("media", path);
        try {
            Response response = HttpClient.postFile(request);
            System.out.println(response.getBodyStr());
            return response.getBodyJson().getString("media_id");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return null;
    }

}
